package com.luoyx.hauyne.admin.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 消息队列配置
 *
 * @author Alan.Luo
 */
@Configuration
public class QueueConfig {

    public static final String USER_PROFILE_UPDATED_EXCHANGE_NAME = "USER_PROFILE_UPDATED_EXCHANGE";

    public static final String USER_PROFILE_UPDATED_QUEUE_NAME = "USER_PROFILE_UPDATED_QUEUE";

    public static final String USER_PROFILE_UPDATED_ROUTING_NAME = "USER_PROFILE_UPDATED_ROUTING";

    /**
     * 通知消息交换机
     *
     * @return 交换机
     */
    @Bean
    public DirectExchange userProfileUpdatedDirectExchange() {
        return new DirectExchange(USER_PROFILE_UPDATED_EXCHANGE_NAME);
    }

    /**
     * 通知消息队列
     *
     * @return 队列
     */
    @Bean
    public Queue userProfileUpdatedQueue() {
        return new Queue(USER_PROFILE_UPDATED_QUEUE_NAME, true);
    }

    @Bean
    public Binding userProfileUpdatedQueueBinding() {
        return BindingBuilder
                .bind(userProfileUpdatedQueue())
                .to(userProfileUpdatedDirectExchange())
                .with(USER_PROFILE_UPDATED_ROUTING_NAME);
    }

    /*~ START 登录历史 MQ配置 ***************************/

    @Bean
    public DirectExchange loginHistoryDirectExchange() {
        return new DirectExchange("LOGIN_HISTORY_EXCHANGE");
    }

    @Bean
    public Queue loginHistoryQueue() {
        return new Queue("LOGIN_HISTORY_QUEUE", true);
    }

    @Bean
    public Binding loginHistoryQueueBinding() {
        return BindingBuilder
               .bind(loginHistoryQueue())
               .to(loginHistoryDirectExchange())
               .with("LOGIN_HISTORY_ROUTING");
    }

    /*~ END   登录历史 MQ配置 ***************************/
}
